package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.UAccount;
import com.wanbangee.marksystem.entities.UTeacher;
import com.wanbangee.marksystem.service.UTeacherService;

@RestController
@RequestMapping("/teacherManage")
public class UTeacherController {

	@Autowired
	private UTeacherService uTeacherService;

	@PostMapping("/insertTeacher")
	public Map<String, Object> addTeacher(UTeacher uTeacher) {
		Map<String, Object> map = new HashMap<>();
		map.put("teaId", uTeacherService.addTeacher(uTeacher));
		map.put("code", 1001);
		map.put("msg", "新增成功");
		return map;
	}

	@DeleteMapping("/deleteTeacher")
	public Map<String, Object> deleteTeacher(Integer teaId) {
		System.out.println(teaId);
		Map<String, Object> map = new HashMap<>();
		int code = uTeacherService.deleteTeacher(teaId);
		if (code != 1001) {
			map.put("code", code);
			map.put("msg", "删除失败");
			return map;
		}
		map.put("code", code);
		map.put("msg", "删除成功");
		return map;
	}


	@PutMapping("/updateTeacher")
	public Map<String, Object> updateTeacher(UTeacher uteacher) {

		Map<String, Object> map = new HashMap<>();

		map.put("code", uTeacherService.updateTeacher(uteacher));
		map.put("msg", "操作成功");

		return map;
	}

	@GetMapping("/selectTeacherByTeaId")
	public Map<String, Object> selectTeacherByTeaId(Integer teaId) {

		Map<String, Object> map = new HashMap<>();
		UTeacher uTeacher = this.uTeacherService.selectTeacherByTeaId(teaId);
		map.put("uTeacher", uTeacher);
		map.put("code", 1001);
		map.put("msg", "操作成功");

		return map;
	}

	@GetMapping("/selectTeacherBySchId")
	public Map<String, Object> selectTeacherBySchId(Integer schId, Integer pageNum, Integer pageSize) {

		Map<String, Object> map = new HashMap<>();
		List<UTeacher> uTeacher = this.uTeacherService.selectTeacherBySchId(schId, pageNum, pageSize);
		map.put("total", this.uTeacherService.selectCountTeacherBySchId(schId));
		map.put("uTeacher", uTeacher);
		map.put("code", 1001);
		map.put("msg", "操作成功");

		return map;
	}

	@GetMapping("/selectTeacherBySchIdAndSubId")
	public Map<String, Object> selectTeacherBySchIdAndSubId(Integer schId, Integer subId, Integer pageNum,
			Integer pageSize) {

		Map<String, Object> map = new HashMap<>();
		List<UTeacher> uTeacher = this.uTeacherService.selectTeacherBySchIdAndSubId(schId, subId, pageNum, pageSize);
		map.put("uTeacher", uTeacher);
		map.put("code", 1001);
		map.put("msg", "操作成功");

		return map;
	}

	@GetMapping("/selectTeacherByaccId")
	public Map<String, Object> selectTeacherByaccId(Integer accId) {

		Map<String, Object> map = new HashMap<>();
		UTeacher uTeacher = this.uTeacherService.selectTeacherByaccId(accId);
		map.put("uTeacher", uTeacher);
		map.put("code", 1001);
		map.put("msg", "操作成功");

		return map;
	}

	@GetMapping("/selctTeacherByTeaNmAndSchId")
	public Map<String, Object> selctTeacherByTeaNmAndSchId(String teaNm, Integer schId) {

		Map<String, Object> map = new HashMap<>();
		List<UTeacher> uTeacher = this.uTeacherService.selctTeacherByTeaNmAndSchId(teaNm, schId);
		map.put("uTeacher", uTeacher);
		map.put("code", 1001);
		map.put("msg", "操作成功");

		return map;
	}
}
